import request from "@/utils/request";

/**
 * 预警规则相关接口封装
 */
export const warningRulesApi = {
  /**
   * 新增预警规则
   * @param {Object} rule - 预警规则对象
   * @returns {Promise}
   */
  add: (rule) => {
    return request.post("/warningRules/add", rule);
  },

  /**
   * 更新预警规则
   * @param {Object} rule - 预警规则对象
   * @returns {Promise}
   */
  update: (rule) => {
    return request.post("/warningRules/update", rule);
  },

  /**
   * 删除预警规则（根据ID）
   * @param {Number} id - 规则ID
   * @returns {Promise}
   */
  deleteById: (id) => {
    return request.delete(`/warningRules/${id}`);
  },

  /**
   * 批量删除预警规则
   * @param {Array<Number>} ids - 要删除的规则ID数组
   * @returns {Promise}
   */
  batchDelete: (ids) => {
    return request.post("/warningRules/batchDelete", ids);
  },

  page: (current, size, recordType) => {
    return request.get('/warningRules/page', {
      params: { current, size, recordType }
    });
  },
   /**
   * 获取所有已存在的数据类型
   * @returns {Promise}
   */
  getExistingTypes: () => {
    return request.get("/warningRules/existingTypes");
  },

  /**
   * 获取所有预警规则
   * @returns {Promise}
   */
  getAll: () => {
    return request.get("/warningRules/all");
  },

  /**
   * 获取所有启用的预警规则
   * @returns {Promise}
   */
  getAllActive: () => {
    return request.get("/warningRules/active");
  },

  /**
   * 根据数据类型获取启用的规则
   * @param {String} recordType - 健康数据类型（如 血压、血糖）
   * @returns {Promise}
   */
  getActiveByType: (recordType) => {
    return request.get(`/warningRules/active/${recordType}`);
  },

  /**
   * 根据ID查询预警规则
   * @param {Number} id - 规则ID
   * @returns {Promise}
   */
  getById: (id) => {
    return request.get(`/warningRules/${id}`);
  },

  /**
   * 预警检测接口
   * @param {Object} healthRecord - 健康记录对象
   * @returns {Promise}
   */
  checkAndWarn: (healthRecord) => {
    return request.post("/warningRules/warning", healthRecord);
  }
};

export default warningRulesApi;